package com.yuan.service;

import com.yuan.dao.LinkManDao;
import com.yuan.pojo.LinkMan;
import com.yuan.pojo.PageBean;

import java.util.LinkedList;
import java.util.List;

public class LinkManService {

    private LinkManDao linkManDao =new LinkManDao();



    public List<LinkMan> findAll() throws Exception {
        return linkManDao.findAll();
    }

    public LinkMan findOne(Integer id) throws Exception {
        return linkManDao.findOne(id);
    }

    public void add(LinkMan linkMan) throws Exception {
        linkManDao.add(linkMan);
    }

    public void delete(Integer id) throws Exception {
        linkManDao.delete(id);
    }

    public void update(LinkMan linkMan) throws Exception {
        linkManDao.update(linkMan);
    }

    public PageBean findByPage(Long currentPage, Long pageSize) throws Exception {
        PageBean pageBean = new PageBean();
        //当前页
        pageBean.setCurrentPage(currentPage);
        //每页条数
        pageBean.setPageSize(pageSize);
        //总条数
        Long totalSize = linkManDao.findTotalSize();
        pageBean.setTotalSize(totalSize);
        //总页数
        Long totalPage=totalSize%pageSize==0?totalSize/pageSize:totalSize/pageSize+1;
        pageBean.setTotalPage(totalPage);
        //每页数据集合
        List<LinkMan> pageList = linkManDao.findPageList(currentPage, pageSize);
        pageBean.setList(pageList);
        return pageBean;
    }
}
